package frontend.pages.reports.workperemployee;

import backend.model.worklog.WorkLog;
import backend.service.worklog.WorkLogService;
import frontend.components.other.EmployeeSelectionPanel;
import frontend.core.TimeTrackingWebApplication;
import frontend.model.reports.ReportInputUIModel;
import frontend.pages.reports.base.AbstractReportForm;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.panel.Panel;

import java.util.List;

public class WorkPerEmployeeReportForm extends AbstractReportForm<WorkLog> {

    public static final String PAGES_WORK_PER_EMPLOYEE_REPORT_FORM_EMPLOYEE = "pages.workPerEmployeeReport.form.employee";

    public WorkPerEmployeeReportForm(String id, ReportInputUIModel model, List<WorkLog> reportResults, WebMarkupContainer workLogListContainer) {
        super(id, model, reportResults, workLogListContainer);
    }

    @Override
    protected void addAdditionalFilteringComponents() {
        Panel employeeSelectionPanel = new EmployeeSelectionPanel("employeeSelection", uiModel, null, PAGES_WORK_PER_EMPLOYEE_REPORT_FORM_EMPLOYEE, false);
        add(employeeSelectionPanel);
    }

    @Override
    protected List<WorkLog> retrieveReportDataFromDatabase() {
        WorkLogService workLogService = TimeTrackingWebApplication.getService(WorkLogService.class);
        List<WorkLog> workLogListFromDB = workLogService.loadWorkLogForTimeIntervalAndEmployee(uiModel.getEmployee(),
                uiModel.getStartDate(), uiModel.getEndDate());
        return workLogListFromDB;
    }

    @Override
    protected void doFormValidation() {
        super.doFormValidation();
        validateNotEmpty(uiModel.getEmployee(), PAGES_WORK_PER_EMPLOYEE_REPORT_FORM_EMPLOYEE);
    }
}
